#include <iostream>
#include <memory>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
using std::unique_ptr;

class Point
{
public:
    Point(int ix = 0,int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int=0,int=0)" << endl;
    }

    void print() const{
        cout << "(" << _ix
            << "," << _iy
            << ")" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl; 
    }
private:
    int _ix;
    int _iy;
};

void test1(){
    unique_ptr<Point> up(new Point(4,9));
    vector<unique_ptr<Point>> vec;
    //往vector当中存左值，会发生复制
    //但是unique_ptr的拷贝构造已经删除
    /* vec.push_back(up); */
    vec.push_back(std::move(up));
    vec.push_back(unique_ptr<Point>(new Point(2,8)));
}


void test0(){
    unique_ptr<int> up(new int(10));
    cout << "*up:" << *up << endl;
    cout << "up.get():" << up.get() << endl;

    cout << endl;

    //unique_ptr不允许复制或赋值
    /* unique_ptr<int> up2 = up; */
    /* unique_ptr<int> up3(new int(20)); */
    /* up = up3; */
}

int main(void){
    test1();
    return 0;
}
